using Ninject.Planning;
using Ninject.Planning.Bindings;
using Ninject.Selection.Heuristics;
using Ninject.Syntax;

namespace ninject.configurer
{
    public static class ConfigurationExtensions
    {
        public static void ToAppSettings<T>(this IBindingToSyntax<T> bindingBuilder)
        {
            bindingBuilder.BindingConfiguration.ProviderCallback =
                ctx =>
                new AppSettingsProvider(typeof (T), ctx.Kernel.Components.Get<IPlanner>(),
                                          ctx.Kernel.Components.Get<IConstructorScorer>());
            bindingBuilder.BindingConfiguration.Target = BindingTarget.Provider;
        }

        public static void ToAppSettings<I,T>(this IBindingToSyntax<I> bindingBuilder)
        {
            bindingBuilder.BindingConfiguration.ProviderCallback =
                ctx =>
                new AppSettingsProvider(typeof (T), ctx.Kernel.Components.Get<IPlanner>(),
                                          ctx.Kernel.Components.Get<IConstructorScorer>());
            bindingBuilder.BindingConfiguration.Target = BindingTarget.Provider;
        }

        public static void ToConfigSection<T>(this IBindingToSyntax<T> bindingBuilder, string sectionName)
        {
            bindingBuilder.BindingConfiguration.ProviderCallback =
                ctx =>
                new ConfigSectionProvider(sectionName, typeof(T), ctx.Kernel.Components.Get<IPlanner>(),
                                          ctx.Kernel.Components.Get<IConstructorScorer>());
            bindingBuilder.BindingConfiguration.Target = BindingTarget.Provider;
        }

        public static void ToConfigSection<I,T>(this IBindingToSyntax<I> bindingBuilder, string sectionName)
        {
            bindingBuilder.BindingConfiguration.ProviderCallback =
                ctx =>
                new ConfigSectionProvider(sectionName, typeof(T), ctx.Kernel.Components.Get<IPlanner>(),
                                          ctx.Kernel.Components.Get<IConstructorScorer>());
            bindingBuilder.BindingConfiguration.Target = BindingTarget.Provider;
        }

        public static void ToSettings<T>(this IBindingToSyntax<T> bindingBuilder, object settings)
        {
            bindingBuilder.BindingConfiguration.ProviderCallback =
                ctx =>
                new SettingsProvider(settings, typeof(T), ctx.Kernel.Components.Get<IPlanner>(),
                                          ctx.Kernel.Components.Get<IConstructorScorer>());
            bindingBuilder.BindingConfiguration.Target = BindingTarget.Provider;
        }

        public static void ToSettings<I,T>(this IBindingToSyntax<I> bindingBuilder, object settings)
        {
            bindingBuilder.BindingConfiguration.ProviderCallback =
                ctx =>
                new SettingsProvider(settings, typeof(T), ctx.Kernel.Components.Get<IPlanner>(),
                                          ctx.Kernel.Components.Get<IConstructorScorer>());
            bindingBuilder.BindingConfiguration.Target = BindingTarget.Provider;
        }
    }
}